package com.longxi.tianjintianbao.ui.presenter.approval;

import android.support.v4.view.ViewPager;

import com.longxi.tianjintianbao.R;
import com.longxi.tianjintianbao.ui.adapter.ApprovalPagerAdapter;
import com.longxi.tianjintianbao.ui.base.BaseActivity;
import com.longxi.tianjintianbao.ui.base.BasePresenter;
import com.longxi.tianjintianbao.ui.fragment.approval.ApprovalListFragment;
import com.longxi.tianjintianbao.ui.view.approval.IApprovalTabAtView;
import com.longxi.tianjintianbao.utils.MyUtils;

import java.util.ArrayList;
import java.util.List;

public class ApprovalTabAtPresenter extends BasePresenter<IApprovalTabAtView> {

    private ApprovalPagerAdapter approvalPagerAdapter;

    private void initVariable() {
        mCategoryList = new ArrayList<>();
        mCategoryList.add("未审批");
        mCategoryList.add("已审批");
    }

    //tab 标签页
    private List<String> mCategoryList;

    public List<String> getCategoryList() {
        if (mCategoryList == null) {
            mCategoryList = new ArrayList<>();
        }
        return mCategoryList;
    }

    public ApprovalTabAtPresenter(BaseActivity context) {
        super(context);
    }

    public void setBar() {
        mContext.setTitle(MyUtils.getResource().getString(R.string.wdsp));
        mContext.setTvLeft(MyUtils.getString(R.string.home));
        initVariable();
    }

    public void initViewPager(){
        approvalPagerAdapter = new ApprovalPagerAdapter(mContext.getSupportFragmentManager(), getCategoryList());
        getView().getViewPager().setAdapter(approvalPagerAdapter);
        getView().getViewPager().setOffscreenPageLimit(getCategoryList().size() - 1);
        getView().getTabLayout().setDividerWidth(1f);
        getView().getTabLayout().setTabSpaceEqual(true);
        getView().getTabLayout().setViewPager(getView().getViewPager());
    }

    public void refreshFragmentUi() {
        ApprovalListFragment myTaskListFragment = (ApprovalListFragment) approvalPagerAdapter.getCurrentFragment();
        myTaskListFragment.refreshReceiptList();
    }

    @Override
    public void detachView() {
        super.detachView();
        this.approvalPagerAdapter = null;
        this.mCategoryList = null;
    }
}
